<template>
	<view class="details">
		<view class="detailsHead"
			:class="[{'detailsHead1': allMsg.orderState == 2},{'detailsHead3': allMsg.orderState == 3 || allMsg.orderState == 4},{'detailsHead0' : allMsg.orderState == 0 || allMsg.orderState == 1}]">
			<view class="detailsHead-main">
				<view class="detailsHead-state">
					<!-- {{allMsg.orderState | changeorderState}} -->
					<text v-if="allMsg.orderState == 1">待接单</text>
					<text v-else-if="allMsg.orderState == 2">待发货</text>
					<text v-else-if="allMsg.orderState == 3">已发货</text>
					<text v-else-if="allMsg.orderState == 4">已发货</text>
				</view>
				<view class="detailsHead-time">
					下单时间：{{allMsg.createTime}}
				</view>
			</view>

			<view class="detailsHead-address">
				<view class="detailsHead-address-left">
					<image class="detailsHead-address-left-img" src="../../../static/manufacturers/address.png" mode="">
					</image>
				</view>
				<view class="detailsHead-address-right">
					<view class="detailsHead-address-right-top font_blod">
						<text>{{allMsg.orderName}}</text>
						<text style="margin-left: 24rpx;">{{allMsg.orderPhone}}</text>
					</view>
					<view class="detailsHead-address-right-btm">
						{{allMsg.orderAddress}}
					</view>
				</view>
			</view>
		</view>
		<view class="detailsTitle">
			<text class="detailsTitle-txt1"></text>
			<text class="detailsTitle-txt2 font_blod">发货清单</text>
		</view>
		<view class="detailsMain">
			<view class="detailsMain-li" v-for="(item, index) of allMsg.zsyhAgentOrderRelList" :key="index">
				<view class="detailsMain-li-left">
					<image class="detailsMain-li-left-img" @click="previewImage(item.attributeLogo)"
						:src=item.attributeLogo mode=""></image>
				</view>
				<view class="detailsMain-li-right">
					<view class="detailsMain-li-right-one font_blod">
						{{item.partsName}}
					</view>
					<view class="detailsMain-li-right-two">
						<text class="detailsMain-li-right-two-txt" v-if="item.attributeIsPost == 1">包邮 偏远地区补差价</text>
						<text class="baoyou-no" v-else>不包邮</text>
					</view>
					<view class="detailsMain-li-right-three">
						<view class="detailsMain-li-right-three-box">
							<text class="detailsMain-li-right-three-box-danwei">数量：</text>
							<text v-if="allMsg.orderState == 1 || allMsg.orderState == 2"
								class="detailsMain-li-right-three-box-num font_blod">{{item.orderCount}}</text>
							<text v-else
								class="detailsMain-li-right-three-box-num font_blod">{{item.orderSellCount}}</text>
							<text class="detailsMain-li-right-three-box-unit">{{item.partsUnit}}</text>
						</view>
						<view class="">
							<text class="detailsMain-li-right-three-box-danwei">单价：</text>
							<text class="detailsMain-li-right-three-box-money font_blod">￥</text>
							<text v-if="allMsg.orderState == 1 || allMsg.orderState == 2"
								class="detailsMain-li-right-three-box-num font_blod">{{item.orderPrice}}</text>
							<text v-else
								class="detailsMain-li-right-three-box-num font_blod">{{item.orderSellPrice}}</text>
							<text class="detailsMain-li-right-three-box-unit">/{{item.partsUnit}}</text>
						</view>
					</view>
					<view class="detailsMain-li-right-four font_blod">
						<text class="detailsMain-li-right-four-txt1 font_blod">小计:</text>
						<text v-if="allMsg.orderState == 1 || allMsg.orderState == 2"
							class="detailsMain-li-right-four-txt2 font_blod">￥{{NumberMul(item.orderCount, item.orderPrice)}}</text>
						<text v-else
							class="detailsMain-li-right-four-txt2 font_blod">￥{{NumberMul(item.orderSellCount, item.orderSellPrice)}}</text>
					</view>
				</view>
			</view>
		</view>
		<view class="details-btn">
			<view class="details-btn-box">
				<image class="details-btn-img" src="../../../static/manufacturers/btn_1.png" mode=""></image>
				<text class="details-btn-title">合计：</text>
				<view class="flex flex1" v-if="allMsg.orderState == 1">
					<view class=" font_blod">
						<text class="details-btn-txt3">￥</text>
						<text class="details-btn-txt2">{{allMsg.orderBeginMoney}}</text>
					</view>
					<view class="details-btn-jiedan font_blod" @click="gogetOrder">
						去接单
					</view>
				</view>
				<view class="flex1 flex-end" v-else>
					<view class="font_blod"
						v-if="allMsg.orderState == 2">
						<text class="details-btn-txt3">￥</text>
						<text class="details-btn-txt2">{{allMsg.orderBeginMoney}}</text></view>
					<view class="font_blod" v-else>
						<text class="details-btn-txt3">￥</text>
						<text class="details-btn-txt2">{{allMsg.orderEndMoney}}</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import allapi from '../api/index.js'
	export default {
		data() {
			return {
				id: '',
				allMsg: {
					orderState: '',
					createTime: '',
					orderName: '',
					orderPhone: '',
					orderAddress: '',
					zsyhAgentOrderRelList: []
				}
			}
		},
		onLoad(val) {
			if (val.id) {
				this.id = val.id
			}
		},
		mounted() {
			this.getFactoryOrderDetails()
		},
		methods: {
			// 图片预览
			previewImage(item, index) {
				console.log(item);
				let lis = item.split()
				wx.previewImage({
					current: 0, // 当前显示图片的http链接
					urls: lis // 需要预览的图片http链接列表
				})
			},
			getFactoryOrderDetails(id) {
				uni.request({
					url: allapi.getFactoryOrderDetails,
					data: {
						id: this.id
					},
					success: (res) => {
						console.log(res);
						let dat = res.data.data
						this.allMsg = dat
					}
				})
			},
			// 点击去接单
			gogetOrder() {
				let _that = this
				uni.request({
					url: allapi.generateDeliverOrder,
					data: {
						id: this.id
					},
					success: (res) => {
						console.log(res);
						uni.showToast({
							title: res.data.msg,
							icon: 'none'
						})
						_that.getFactoryOrderDetails()
					}
				})
			},
		},
		filters: {
			changeorderState(val) {
				if (val == 1) {
					return '待接单'
				} else if (val == 2) {
					return '待发货'
				} else if (val == 3) {
					return '已发货'
				} else if (val == 4) {
					return '已发货'
				}
			}
		}
	}
</script>

<style scoped>
	.flex1 {
		flex: 1;
	}

	.flex-end {
		text-align: right;
	}

	.flex {
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.details {
		position: absolute;
		width: 100%;
		height: 100%;
		left: 0;
		top: 0;
		display: flex;
		flex-direction: column;
	}

	.detailsHead {
		min-height: 326rpx;
		/* background-image: url('https://www.zzzsyh.com/applets/agent/factory/10.png'); */
		background-size: 100%;
		background-repeat: no-repeat;
		padding-top: 0.1rpx;
		display: flex;
		flex-direction: column;
	}

	.detailsHead0 {
		background-image: url('https://www.zzzsyh.com/applets/agent/factory/10.png');
	}

	.detailsHead1 {
		background-image: url('https://www.zzzsyh.com/applets/agent/factory/9.png');
	}

	.detailsHead3 {
		background-image: url('https://www.zzzsyh.com/applets/agent/factory/10_1.png');
	}

	.detailsHead-main {
		flex: 1;
	}

	.detailsHead-state {
		font-weight: 600;
		font-size: 42rpx;
		color: #FFFFFF;
		margin-left: 48rpx;
		margin-top: 48rpx;
		line-height: 58rpx;
	}

	.detailsHead-time {
		font-size: 24rpx;
		font-weight: 400;
		color: #FFFFFF;
		margin-top: 12rpx;
		margin-left: 48rpx;
		line-height: 34rpx;
	}

	.detailsHead-address {
		margin: 26rpx 24rpx 0;
		background: #FFFFFF;
		display: flex;
		align-items: center;
		padding: 24rpx;
		border-radius: 16rpx;
	}

	.detailsHead-address-left-img {
		width: 40rpx;
		height: 40rpx;
	}

	.detailsHead-address-right {
		flex: 1;
		margin-left: 24rpx;
	}

	.detailsHead-address-right-top {
		font-size: 32rpx;
		color: #333333;
		line-height: 44rpx;
	}

	.detailsHead-address-right-btm {
		margin-top: 16rpx;
		font-size: 28rpx;
		color: #666666;
		font-weight: 400;
		line-height: 40rpx;
	}

	.detailsTitle {
		display: flex;
		align-items: center;
		margin: 26rpx 0;
	}

	.detailsTitle-txt1 {
		width: 10rpx;
		height: 34rpx;
		background: #5DD4D6;
		border-radius: 5rpx;
		display: block;
		margin-left: 24rpx;
	}

	.detailsTitle-txt2 {
		font-size: 32rpx;
		color: #333333;
		margin-left: 24rpx;
	}

	.detailsMain {
		flex: 1;
		background: #FFFFFF;
		margin: 0 24rpx;
		overflow: auto;
		border-top-left-radius: 16rpx;
		border-top-right-radius: 16rpx;
		/* padding-bottom: 120rpx; */
		margin-bottom: 225rpx;
	}

	.detailsMain-li {
		padding: 24rpx 0;
		margin: 0 32rpx;
		border-bottom: 2rpx solid #EEEEEE;
		display: flex;
	}

	.detailsMain-li-left-img {
		width: 160rpx;
		height: 160rpx;
		border-radius: 8rpx;
		background: #EEEEEE;
	}

	.detailsMain-li-right {
		flex: 1;
		margin-left: 32rpx;
	}

	.detailsMain-li-right-one {
		color: #333333;
		font-size: 28rpx;
		line-height: 40rpx;
	}

	.detailsMain-li-right-two {
		margin-top: 16rpx;
	}

	.detailsMain-li-right-two-txt {
		font-size: 24rpx;
		font-weight: 400;
		color: #28CD50;
		line-height: 34rpx;
		padding: 0 12rpx;
		border-radius: 6rpx;
		border: 2rpx solid #28CD50;
	}

	.detailsMain-li-right-three {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-top: 20rpx;
	}

	.detailsMain-li-right-three-box-danwei {
		font-size: 24rpx;
		font-weight: 400;
		color: #333333;
	}

	.detailsMain-li-right-three-box-money {
		font-size: 24rpx;
		color: #333333;
	}

	.detailsMain-li-right-three-box-num {
		font-size: 32rpx;
		color: #333333;
	}

	.detailsMain-li-right-three-box-unit {
		font-size: 24rpx;
		font-weight: 400;
		color: #666666;
	}

	.detailsMain-li-right-four {
		display: flex;
		justify-content: flex-end;
		margin-top: 22rpx;
	}

	.detailsMain-li-right-four-txt1 {
		font-size: 28rpx;
		color: #333333;
	}

	.detailsMain-li-right-four-txt2 {
		font-size: 32rpx;
		color: #EF691C;
	}

	.details-btn {
		display: flex;
		justify-content: center;
		align-items: center;
		position: fixed;
		bottom: 68rpx;
		width: 100%;
		z-index: 666;
	}

	.details-btn-box {
		width: 686rpx;
		padding: 0 16rpx;
		height: 120rpx;
		background: #313131;
		border-radius: 24rpx;
		display: flex;
		align-items: center;
	}

	.details-btn-img {
		width: 74rpx;
		height: 94rpx;
	}

	.details-btn-title {
		font-size: 28rpx;
		color: #FFFFFF;
		font-weight: 400;
		margin-left: 16rpx;
	}

	.details-btn-txt {
		font-size: 36rpx;
		color: #FF9300;
		display: flex;
		text-align: right;
		margin-right: 16rpx;
	}

	.details-btn-txt2 {
		font-size: 36rpx;
		color: #FF9300;
		text-align: right;
		margin-right: 16rpx;
	}

	.details-btn-txt3 {
		font-size: 28rpx;
		color: #FF9300;
		text-align: right;
		/* margin-right: 16rpx; */
	}

	.details-btn-jiedan {
		width: 184rpx;
		height: 72rpx;
		line-height: 72rpx;
		text-align: center;
		background: #5DD4D6;
		border-radius: 36rpx;
		font-size: 24rpx;
		color: #FFFFFF;
	}
</style>
